package com.ctrip.demo.leetcode;

/**
 * @author xs.wu
 */
public class LeetCode686 {

    public static void main(String[] args) {

        String a = "abc";
        String b = "cabcabca";
        System.out.println(repeatedStringMatch(a, b));
    }

    public static int repeatedStringMatch(String a, String b) {

        String[] bArr = b.split("");

        for(String str : bArr) {
            if(!a.contains(str)) {
                return -1;
            }
        }
        StringBuffer temp = new StringBuffer();
        int res = 0;
        while (temp.length() < b.length()) {
            temp.append(a);
            res += 1;
        }

        if (temp.toString().contains(b)) {
            return res;
        }
        temp.append(a);
        if (!temp.toString().contains(b)) {
            return -1;
        }

        return res + 1;

    }
}
